package com.amit.jdbc.mysql;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Lab7 {
	
	


	public static void main(String[] args) throws Exception {
		
		Connection con=null;
		
		//.loading the driver class
		try {
			Class.forName("com.mysql.jdbc.Driver");
			//Class.forName("oracle.jdbc.driver.OracleDriver");
			
			
		//2.create the connection
			
			 con=DriverManager.getConnection("jdbc:mysql://localhost:3306/amit007","root","root");
			//con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","root","root");
			
			//3.create the sql statement
			
			System.out.println("Enter id");
			Scanner sc=new Scanner(System.in);
			int id=sc.nextInt();
			
			String qry=String.format("select * from jlcstudents where id=%d", id);
			
			//4.create jdnc statement
			Statement st=con.createStatement();
			
			//5.submit the jdbc statement
			
			ResultSet rs=st.executeQuery(qry);
			
			//6.process the result
			
			if(rs.next())
			{
				 id=rs.getInt(1);
				 String name=rs.getString(2);
				 String email=rs.getString(3);
				 long phone=rs.getLong(4);
				 float  fee=rs.getFloat(5);
				 Date dob=rs.getDate(6);
				 
				 System.out.println(id+" "+name+" "+ email+" "+phone+" "+fee+" "+dob);
				
			}
			else
			{
				System.out.println("no record");
			}
			
			
		} catch (Exception e) {
			
			con.close();
			
			e.printStackTrace();
		}
		
		

	}

}
